package com.cinyi.ormlite.dao;

import java.util.List;

import com.cinyi.ormlite.core.BaseModel;

@SuppressWarnings("rawtypes")
public class SQLModel<T extends BaseModel> implements java.io.Serializable{

	private int action = 0 ;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4056094656937140555L;
	private Class<?> clazz = null ;
	private String id = null ;
	private String sql = null ;
	private List<Object> data = null ;
	private int pageIndex = 0 ;
	private int rows = 10 ;
	
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
	public List<Object> getData() {
		return data;
	}
	public void setData(List<Object> data) {
		this.data = data;
	}
	
	public boolean isValid() {
		return sql!=null && sql.length()>0;
	}
	public int getAction() {
		return action;
	}
	public void setAction(int action) {
		this.action = action;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public Class<?> getClazz() {
		return clazz;
	}
	public void setClazz(Class<?> clazz) {
		this.clazz = clazz;
	}
	public String toSQL(){
		if(sql.toLowerCase().indexOf("limit") == -1) {
			sql += " LIMIT " + pageIndex + "," + rows ;
		}
		
		return sql ;
		
	}
	
}
